<script setup lang="ts">
import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
import { getCurrentInstance } from 'vue'
//@ts-ignore
const { proxy } = getCurrentInstance()
onLaunch(() => {
  console.log('App Launch')
  let systemInfoSync = uni.getSystemInfoSync()
  console.log(systemInfoSync)
})
onShow(() => {
  console.log('App Show')
  // #ifdef APP-PLUS
  // 检查是否支持指纹识别 支持则调用 checkIsSoterEnrolledInDeviceFingerPrint 方法进行验证
  checkIsSoterEnrolledInDeviceFingerPrint()
  // #endif

  // #ifndef APP-PLUS
    proxy?.$isResolve() // 触发 resolve
  // #endif
})
onHide(() => {
  console.log('App Hide')
})

const checkIsSoterEnrolledInDeviceFingerPrint = () => {
  uni.checkIsSoterEnrolledInDevice({
    checkAuthMode: 'fingerPrint',
    success(res) {
      console.log('success')
      console.log(res)
      startSoterAuthenticationFingerPrint()
    },
    fail(err) {
      console.log('fail')
      console.log(err)
      uni.showToast({
        title: '当前设备不支持指纹识别',
        icon: 'none', // 设置为 "none" 表示没有图标，只显示文字
        duration: 1000, // 持续时间（毫秒）
      });
    },
    complete(res) {
      console.log('complete')
      console.log(res)
    },
  })
}

const startSoterAuthenticationFingerPrint = () => {
  uni.startSoterAuthentication({
    requestAuthModes: ['fingerPrint'],
    challenge: '123456',
    authContent: '请用指纹解锁',
    success(res) {
      console.log('success,进入首页')
      console.log(res)
      proxy?.$isResolve() // 触发 resolve
      // 进入首页
    },
    fail(err) {
      console.log('fail,重试')
      console.log(err)
      uni.showToast({
        title: '指纹识别失败,请重试',
        icon: 'none', // 设置为 "none" 表示没有图标，只显示文字
        duration: 1000, // 持续时间（毫秒）
      });
      // 重试
      startSoterAuthenticationFingerPrint()
    },
    complete(res) {
      console.log(res)
    },
  })
}
</script>

<style lang="scss">
// 字体图标
@import '@/styles/fonts.scss';
/* uni.css - 通用组件、模板样式库，可以当作一套ui库应用 */
@import './common/uni.css';
@import '@/uni.scss';
view,
navigator,
input,
scroll-view {
  box-sizing: border-box;
}

button::after {
  border: none;
}

swiper,
scroll-view {
  flex: 1;
  height: 100%;
  overflow: hidden;
}

image {
  width: 100%;
  height: 100%;
  vertical-align: middle;
}

// 两行省略
.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
</style>
